//
//  OEHowItWorksViewController.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/5.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEHowItWorksViewController.h"
#import "OEHaoItWorkTableViewCell.h"
@interface OEHowItWorksViewController ()
@property(nonatomic, strong) NSMutableArray                     *dataSouce;/**<  */
@end

@implementation OEHowItWorksViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = OESTRING(@"HAO IT WORKS");
    [self configDataSouce];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configDataSouce{
    self.dataSouce = NSMutableArray.new;
    NSString * string = @"1 Here is the guide for using cups.Here is the guide for usingcups.Here is the guide for using cups.\n2 Here is the guide for using cups.Here is the guide for usingcups.\n3 Here is the guide for using cups.Here is the guide for usingcups.Here is the guide for using cups.\n 4.Here is the guide for using cups.";
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"1. HOW TO LEASE A CUP" detailString:string];
        [self.dataSouce addObject:model];
    });
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"2. HOW TO RETURN THE CUP" detailString:string];
        [self.dataSouce addObject:model];
    });
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"1. HOW TO BUY COFFEE" detailString:string];
        [self.dataSouce addObject:model];
    });
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"1. HOW TO BECOME A MENMBER" detailString:string];
        [self.dataSouce addObject:model];
    });
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"1. HOW TO WITHDRAW DEPOSIT" detailString:string];
        [self.dataSouce addObject:model];
    });
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    if (model.isSlected) {
        if (!model.height) {
            [self tableView:tableView cellForRowAtIndexPath:indexPath];
        }
        return model.height;
    }
    return OEHaoItWorkTableViewCell.cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    OEHaoItWorkTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[OEHaoItWorkTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    cell.model = model;
    __weak typeof(self) weakSelf =  self;
    [cell.openButton setClicAction:^(UIButton *sender) {
        model.isSlected = !model.isSlected;
        [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    }];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
